package com.greateamd.timetableasy.server.services;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.greateamd.timetableasy.client.services.room.RoomService;
import com.greateamd.timetableasy.domain.Room;
import com.greateamd.timetableasy.domain.exceptions.DBServerSideException;
import com.greateamd.timetableasy.server.dao.RoomDAO;

@Service("roomService")
public class RoomServiceImpl implements RoomService {

	private RoomDAO roomDAO;
	public void setRoomDAO(RoomDAO roomDAO) {
		this.roomDAO = roomDAO;
	}
	
	@Override
	public boolean save(Room room) throws DBServerSideException {
		try {
			roomDAO.save(room);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
		return true;
	}

	@Override
	public Room find(int id) throws DBServerSideException{
		try {
			return roomDAO.getById(id);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public List<Room> getAll() throws DBServerSideException {
		try {
			return roomDAO.getAll();
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public List<Room> getAllOfLoggedUser() throws DBServerSideException {
		try {
			return roomDAO.getAllOfLoggedUser();
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}
	
	@Override
	public boolean remove(Room room) throws DBServerSideException {
		try {
			roomDAO.delete(room);
			return true;
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public boolean update(Room room) throws DBServerSideException {
		try {
			roomDAO.update(room);
			return true;
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public boolean getDisponibility(Integer excluseThisEventId,String room, Date from, int duration) throws DBServerSideException {
		try {
			return roomDAO.getDisponibility(excluseThisEventId,room, from, duration);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}
}
